﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace TimeReporter
{
    public static class FirstDayInWeek
    {
                public static DateTime GetFirstDateOfWeek(DateTime dayInWeek)

        {

            CultureInfo defaultCultureInfo = CultureInfo.CurrentCulture;

            return GetFirstDateOfWeek(dayInWeek, defaultCultureInfo);

        }

        public static DateTime GetFirstDateOfWeek(DateTime dayInWeek, CultureInfo cultureInfo)

        {

            DayOfWeek firstDay = cultureInfo.DateTimeFormat.FirstDayOfWeek;

            DateTime firstDateInWeek = dayInWeek.Date;

            while (firstDateInWeek.DayOfWeek != firstDay)

                firstDateInWeek = firstDateInWeek.AddDays(-1);

            return firstDateInWeek;

        }

    }
    
}
